import Mock from 'mockjs2'
import { builder, getBody } from '../util'
import { userApi } from '@/api/user.js'

const username = ['admin', 'super']
const password = ['123456']

/**
 * 登录
 */
const login = (options) => {
  const body = getBody(options)
  console.log('mock: body', body)
  if (!username.includes(body.username) || !password.includes(body.password)) {
    return builder({
      isLogin: true
    }, '账户或密码错误', 401)
  }

  return builder({
    'id': Mock.mock('@guid'),
    'name': Mock.mock('@name'),
    'username': 'admin',
    'Access-Token': '4291d7da9005377ec9aec4a71ea837f'
  }, '', 200, {
    'Custom-Header': Mock.mock('@guid')
  })
}

/**
 * 退出登录
 */
const logout = () => {
  return builder({}, '[测试接口] 注销成功')
}

/**
 * 用户菜单(后台动态)
 */
const userMenu = (options) => {
  const userMenuData = [
    // 业务受理
    {
      'menuId': Mock.mock('@guid'),
      'menuName': '开发演示',
      'view': 'demo',
      'icon': 'video-camera',
      'url': '',
      'children': [{
        'menuId': Mock.mock('@guid'),
        'menuName': 'PDF预览',
        'view': 'PdfDemo',
        'icon': '',
        'url': '/development/pdf/index'
      },
      {
        'menuId': Mock.mock('@guid'),
        'menuName': '表格演示',
        'icon': '',
        'view': 'GridDemo',
        'url': '/development/grid/index'
      }
      ]
    }
  ]
  const json = builder(userMenuData)
  console.log('json', json)
  return json
}

Mock.mock(userApi.login, 'post', login)
Mock.mock(userApi.logout, 'post', logout)
Mock.mock(userApi.userMenus, 'post', userMenu)
Mock.mock(userApi.userInfo, 'post', userMenu)
